
**********************************************
*TABLE 6: Ownership transitions, 2004 to 2006 
**********************************************
set more off
*Baseline
use "Regressions Data/baseline0406_nown.dta",clear

reg dfo orange gray lemp tfp privatized sec1-sec10
gen s=1 if e(sample)
bysort okpo: egen s2=max(s)
keep if s2==1

gen noff=1 if foreign_in_chain==1 & offshore==0
replace noff=0 if noff==.

replace year=2005 if year==2006
tsset okpo year
gen dnoff=noff-l.noff
replace dfo=. if year==2004
replace doff=. if year==2004

bysort okpo: egen dfo2=max(dfo)
bysort okpo: egen doff2=max(doff)
keep if year==2004

gen do_fo=1 if dfo2==1
gen do_off=1 if doff2==1 & foreign_in_chain==0
gen noff_off=1 if doff2==1 & foreign_in_chain==1 & offshore==0 
gen fo_do=1 if dfo2==-1
gen do=1 if foreign_in_chain==0

preserve
collapse (sum) do_fo do_off noff_off fo_do foreign_in_chain do noff , by(color)
gen do_fo2=do_fo/do
gen do_off2=do_off/do
gen noff_off2=noff_off/noff
gen fo_do2=fo_do/foreign_in_chain
keep color do_fo2 do_off2 noff_off2 fo_do2
tempfile color_trans
save `color_trans'
restore
collapse (sum) do_fo do_off noff_off fo_do foreign_in_chain do noff
gen do_fo2=do_fo/do
gen do_off2=do_off/do
gen noff_off2=noff_off/noff
gen fo_do2=fo_do/foreign_in_chain
keep do_fo2 do_off2 noff_off2 fo_do2
append using `color_trans'
gen group="All"
replace group="Blue" if color==1
replace group="Orange" if color==2 
replace group="Gray" if color==3
replace color=0 if color==.
sort color
drop color
order group do_fo2 do_off2 noff_off2 fo_do2
label var group "Group"
label var do_fo2 "DO=>FO"
label var do_off2 "DO=>OFF"
label var noff_off2 "NOFF=>OFF"
label var fo_do2 "FO=>DO"
tostring do_fo2 do_off2 noff_off2 fo_do2, replace force format(%9.3f)
export excel "Results/Table6_baseline.xls", firstrow (varlabels) replace


*JSCReg only
use "Regressions Data/JSCReg0406_nown.dta",clear
reg dfo orange gray lemp tfp privatized sec1-sec10
gen s=1 if e(sample)
bysort okpo: egen s2=max(s)
keep if s2==1

gen noff=1 if foreign_in_chain==1 & offshore==0
replace noff=0 if noff==.

replace year=2005 if year==2006
tsset okpo year
gen dnoff=noff-l.noff
replace dfo=. if year==2004
replace doff=. if year==2004

bysort okpo: egen dfo2=max(dfo)
bysort okpo: egen doff2=max(doff)
keep if year==2004

gen do_fo=1 if dfo2==1
gen do_off=1 if doff2==1 & foreign_in_chain==0
gen noff_off=1 if doff2==1 & foreign_in_chain==1 & offshore==0 
gen fo_do=1 if dfo2==-1
gen do=1 if foreign_in_chain==0

preserve
collapse (sum) do_fo do_off noff_off fo_do foreign_in_chain do noff , by(color)
gen do_fo2=do_fo/do
gen do_off2=do_off/do
gen noff_off2=noff_off/noff
gen fo_do2=fo_do/foreign_in_chain
keep color do_fo2 do_off2 noff_off2 fo_do2
tempfile color_trans
save `color_trans'
restore
collapse (sum) do_fo do_off noff_off fo_do foreign_in_chain do noff
gen do_fo2=do_fo/do
gen do_off2=do_off/do
gen noff_off2=noff_off/noff
gen fo_do2=fo_do/foreign_in_chain
keep do_fo2 do_off2 noff_off2 fo_do2
append using `color_trans'
gen group="All"
replace group="Blue" if color==1
replace group="Orange" if color==2 
replace group="Gray" if color==3
replace color=0 if color==.
sort color
drop color
order group do_fo2 do_off2 noff_off2 fo_do2
label var group "Group"
label var do_fo2 "DO=>FO"
label var do_off2 "DO=>OFF"
label var noff_off2 "NOFF=>OFF"
label var fo_do2 "FO=>DO"
tostring do_fo2 do_off2 noff_off2 fo_do2, replace force format(%9.3f)
export excel "Results/Table6_JSCReg.xls", firstrow (varlabels) replace


